package com.example.myapplication.logs;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;

import java.util.List;

@Dao
public interface LogDao {
    @Insert
    long insertPower(PowerEvent event);

    @Insert
    long insertBrowse(BrowseEvent event);

    @Insert
    long insertChat(ChatMessage message);

    @Query("SELECT * FROM power_events ORDER BY timestamp DESC LIMIT 200")
    List<PowerEvent> getRecentPower();

    @Query("SELECT * FROM browse_events ORDER BY timestamp DESC LIMIT 200")
    List<BrowseEvent> getRecentBrowse();

    @Query("SELECT * FROM chat_messages ORDER BY timestamp DESC LIMIT 200")
    List<ChatMessage> getRecentChat();

    // 开机时长统计相关查询
    @Query("SELECT * FROM power_events WHERE type = 'boot' ORDER BY timestamp DESC LIMIT 1")
    PowerEvent getLastBootEvent();

    @Query("SELECT * FROM power_events WHERE type = 'shutdown' AND timestamp > :bootTimestamp ORDER BY timestamp ASC LIMIT 1")
    PowerEvent getShutdownAfterBoot(long bootTimestamp);

    @Query("SELECT * FROM power_events WHERE type = 'boot' ORDER BY timestamp DESC LIMIT :limit")
    List<PowerEvent> getRecentBootEvents(int limit);

    @Query("SELECT * FROM power_events WHERE type = 'shutdown' ORDER BY timestamp DESC LIMIT :limit")
    List<PowerEvent> getRecentShutdownEvents(int limit);

    // 清除所有电源事件数据
    @Query("DELETE FROM power_events")
    void clearAllPowerEvents();
}






